import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Scanner;

class AveragePrise {
    public static void main(String args[]) {
        File file = new File("123.txt");
        Scanner sc = null;
        int count = 0;
        double sum = 0;

        try {
            double score = 0;
            sc = new Scanner(file);
            sc.useDelimiter("[^0123456789.]+");

            while (sc.hasNextDouble()) {
                score = sc.nextDouble();
                count++;
                sum = sum + score;
            }

            double aver = sum / count;
            String averCost = String.format("%.3f", aver);
            System.out.println("平均价钱：" + averCost + "元");
            FileWriter fw = new FileWriter(file, true);
            PrintWriter pw = new PrintWriter(fw);
            pw.println("平均价钱：" + averCost + "元");
            pw.close();
            fw.close();
        } catch (IOException exp) {
            System.out.println("计算出错或文件写入失败：" + exp.getMessage());
        } finally {
            if (sc!= null) {
                sc.close();
            }
        }
    }
}